package com.issac.service.serviceImpl;

import com.issac.common.R;
import com.issac.entity.Retailer;
import com.issac.mapper.RetailerMapper;
import com.issac.service.RetailerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName RetailerService
 * @Author zy
 * @Date 2021/10/29 11:49
 * @Description RetailerService
 * @Version 1.0
 */
@Service
public class RetailerServiceImpl implements RetailerService {
    @Autowired
    RetailerMapper retailerMapper;

    @Override
    public R addRetailer(Retailer retailer) {
        int result = 0;
        try {
            result = retailerMapper.insert(retailer);
            return R.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(result);
        }
    }

    @Override
    public R selectAllRetailer() {
        List<Retailer> list = null;
        try {
            list = retailerMapper.selectList(null);
            return R.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查找失败");
        }
    }

    @Override
    public R updateRetailer(Retailer retailer) {
        try {
            int result = retailerMapper.updateById(retailer);
            return R.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("更新失败");
        }
    }

    @Override

    public R deleteRetailerById(String id) {
        try {
            int result = retailerMapper.deleteById(id);
            return R.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("删除失败");
        }
    }
}